//
//  LYBusinessCardView.m
//  SelectCity
//
//  Created by liuyan on 2019/3/28.
//  Copyright © 2019年 liuyan. All rights reserved.
//

#import "LYBusinessCardView.h"

@interface LYBusinessCardView()

@property (nonatomic, strong) UIImageView *backView; //背景图
@property (nonatomic, strong) UIImageView *iconImage; //头像
@property (nonatomic, strong) UIImageView *codeImage; //二维码
@property (nonatomic, strong) UILabel *nameLabel; // 姓名
@property (nonatomic, strong) UILabel *companyLabel; // 公司/职位

//企业
@property (nonatomic, strong) UILabel *landlineLabel; //公司座机
@property (nonatomic, strong) UILabel *companymobileLabel; //移动电话
@property (nonatomic, strong) UILabel *companyEmailLabel; //邮箱
@property (nonatomic, strong) UILabel *companyURLLabel; //网址

//个人
@property (nonatomic, strong) UILabel *educationLabel; //学历
@property (nonatomic, strong) UILabel *mobileLabel; //电话
@property (nonatomic, strong) UILabel *emailLabel; //邮件
@property (nonatomic, strong) UILabel *weixinLabel; //微信号

@property (nonatomic, strong) UILabel *bottomLabel;// 个人标签/公司地址

@end

@implementation LYBusinessCardView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI];
    }
    return self;
}
- (void)initUI {
//    CGFloat height = (WIDTH- 40.0*Scale)* 685/1005;

    self.backView = [[UIImageView alloc] initWithFrame:self.bounds];
    [self addSubview:self.backView];
    self.backView.contentMode = UIViewContentModeScaleAspectFill;
    
    self.iconImage = [UIToolsControl initImageViewWithFrame:CGRectMake(25.0*Scale, 15*Scale, 64.0*Scale, 64.0*Scale) imageName:@"header_bg"];
    self.iconImage.contentMode = UIViewContentModeScaleAspectFill;
    self.iconImage.layer.cornerRadius = self.iconImage.height/2;
    self.iconImage.layer.masksToBounds = YES;
    [self addSubview:self.iconImage];
    
    self.codeImage = [UIToolsControl initImageViewWithFrame:CGRectMake(25*Scale, self.iconImage.bottom + 20*Scale, 74*Scale, 74*Scale) imageName:@"wx_bg"];
    self.codeImage.layer.cornerRadius = 5;
    self.codeImage.layer.masksToBounds = YES;
    [self.backView addSubview:self.codeImage];
    self.codeImage.backgroundColor = THEMECOLOR_OF_GRAY;
    
    self.weixinLabel = [UIToolsControl initLabelWithFrame:CGRectMake(10*Scale, self.codeImage.bottom, 105*Scale, 40*Scale) text:nil textColor:COLOR_OF_WHITE font:Font_13];
    self.weixinLabel.textAlignment = NSTextAlignmentCenter;
//    self.weixinLabel.adjustsFontSizeToFitWidth = YES;
    self.weixinLabel.numberOfLines = 0;
    self.weixinLabel.lineBreakMode = NSLineBreakByWordWrapping;
    [self.backView addSubview:self.weixinLabel];
    
    self.nameLabel = [UIToolsControl initLabelWithFrame:CGRectMake(self.codeImage.right + 25*Scale, 18*Scale, self.width - self.codeImage.right - 35*Scale, 22*Scale) text:nil textColor:COLOR_OF_WHITE font:Font_17];
    self.nameLabel.adjustsFontSizeToFitWidth = YES;
    [self.backView addSubview:self.nameLabel];
    
    self.companyLabel = [UIToolsControl initLabelWithFrame:CGRectMake(self.nameLabel.left,self.nameLabel.bottom + 5*Scale, self.nameLabel.width , 20*Scale) text:nil textColor:COLOR_OF_WHITE font:Font_15];
    self.companyLabel.adjustsFontSizeToFitWidth = YES;
    [self.backView addSubview:self.companyLabel];
    
    UIView *line1 = [UIToolsControl initViewWithFrame:CGRectMake(self.nameLabel.left,self.companyLabel.bottom + 8*Scale , self.nameLabel.width, 5) backgroundColor:RGBA(255, 255, 255, 0.4)];
    line1.layer.cornerRadius = line1.height/2;
    line1.layer.masksToBounds = YES;
    [self.backView addSubview:line1];
    
    //公司
    self.landlineLabel = [UIToolsControl initLabelWithFrame:CGRectMake(self.nameLabel.left, line1.bottom+25*Scale, self.nameLabel.width , 20*Scale) text:nil textColor:COLOR_OF_WHITE font:Font_14];
    self.landlineLabel.adjustsFontSizeToFitWidth = YES;
    [self.backView addSubview:self.landlineLabel];
    
    self.companymobileLabel = [UIToolsControl initLabelWithFrame:CGRectMake(self.nameLabel.left,self.landlineLabel.bottom, self.nameLabel.width , 20*Scale) text:nil textColor:COLOR_OF_WHITE font:Font_14];
    self.companymobileLabel.adjustsFontSizeToFitWidth = YES;
    [self.backView addSubview:self.companymobileLabel];
    
    self.companyEmailLabel = [UIToolsControl initLabelWithFrame:CGRectMake(self.nameLabel.left,self.companymobileLabel.bottom, self.nameLabel.width , 20*Scale) text:nil textColor:COLOR_OF_WHITE font:Font_14];
    self.companyEmailLabel.adjustsFontSizeToFitWidth = YES;
    [self.backView addSubview:self.companyEmailLabel];
    
    self.companyURLLabel = [UIToolsControl initLabelWithFrame:CGRectMake(self.nameLabel.left,self.companyEmailLabel.bottom, self.nameLabel.width , 20*Scale) text:nil textColor:COLOR_OF_WHITE font:Font_14];
    self.companyURLLabel.adjustsFontSizeToFitWidth = YES;
    [self.backView addSubview:self.companyURLLabel];
    
    //个人
    self.educationLabel = [UIToolsControl initLabelWithFrame:CGRectMake(self.nameLabel.left, line1.bottom + 30*Scale, self.nameLabel.width, 20*Scale) text:nil textColor:COLOR_OF_WHITE font:Font_14];
    self.educationLabel.adjustsFontSizeToFitWidth = YES;
    [self.backView addSubview:self.educationLabel];
    
    self.mobileLabel = [UIToolsControl initLabelWithFrame:CGRectMake(self.nameLabel.left,self.educationLabel.bottom+5*Scale, self.nameLabel.width , 20*Scale) text:nil textColor:COLOR_OF_WHITE font:Font_14];
    self.mobileLabel.adjustsFontSizeToFitWidth = YES;
    [self.backView addSubview:self.mobileLabel];
    
    self.emailLabel = [UIToolsControl initLabelWithFrame:CGRectMake(self.nameLabel.left,self.mobileLabel.bottom+5*Scale, self.nameLabel.width , 20*Scale) text:nil textColor:COLOR_OF_WHITE font:Font_14];
    self.emailLabel.adjustsFontSizeToFitWidth = YES;
    [self.backView addSubview:self.emailLabel];
    
    UIView *line2 = [UIToolsControl initViewWithFrame:CGRectMake(self.nameLabel.left,self.companyURLLabel.bottom + 10*Scale, self.nameLabel.width, 5) backgroundColor:RGBA(255, 255, 255, 0.4)];
    line2.layer.cornerRadius = line1.height/2;
    line2.layer.masksToBounds = YES;
    [self.backView addSubview:line2];
    
    self.bottomLabel = [UIToolsControl initLabelWithFrame:CGRectMake(25*Scale, line2.bottom+10*Scale, self.width - 35*Scale, 40*Scale) text:nil textColor:COLOR_OF_WHITE font:Font_12];
    self.bottomLabel.numberOfLines = 0;
    self.bottomLabel.lineBreakMode = NSLineBreakByWordWrapping;
    self.bottomLabel.adjustsFontSizeToFitWidth = YES;
    [self.backView addSubview:self.bottomLabel];
}
- (void)setModel:(MineBusinessCardBaseModel *)model {
    if (model.avatar && model.avatar.length) {
        [_iconImage sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:[UIImage imageNamed:@"header_bg"]];
    } else {
        _iconImage.image = [UIImage imageNamed:@"header_bg"];
    }
    if (model.weixin_img && model.weixin_img.length) {
        _codeImage.hidden = NO;
        [_codeImage sd_setImageWithURL:[NSURL URLWithString:model.weixin_img]];
        self.weixinLabel.frame = CGRectMake(10*Scale, self.codeImage.bottom, 105*Scale, 40*Scale);
    } else {
        _codeImage.hidden = YES;
        _codeImage.image = [UIImage imageNamed:@"wx_bg"];
        self.weixinLabel.frame = CGRectMake(10*Scale, self.iconImage.bottom+10*Scale, 105*Scale, 40*Scale);
    }
    
    if ([model.type integerValue] == 1) { //公司
//        _backView.image = [UIImage imageNamed:@"mingpian_qiye"];
        if (model.skin_img && model.skin_img.length) {
            [self.backView sd_setImageWithURL:[NSURL URLWithString:model.skin_img] placeholderImage:[UIImage imageNamed:@"mingpian_geren"]];
        } else {
            _backView.image = [UIImage imageNamed:@"mingpian_qiye"];
        }
        
        _weixinLabel.hidden = YES;
        NSMutableAttributedString *positionstr = [[NSMutableAttributedString alloc] initWithString:model.name];
        NSString *position = model.position;
        if (position.length) {
            NSAttributedString *strq = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"（%@）",position] attributes:@{NSForegroundColorAttributeName :[UIColor whiteColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:12]}];
            [positionstr appendAttributedString:strq];
        }
        _nameLabel.attributedText = positionstr;
        _companyLabel.text = model.company_info.full_name;
        
        self.landlineLabel.hidden = NO;
        self.landlineLabel.text = [NSString stringWithFormat:@"公司座机：%@", model.company_info.landline_tel];
        self.companymobileLabel.hidden = NO;
        self.companymobileLabel.frame = CGRectMake(self.nameLabel.left,self.landlineLabel.bottom, self.nameLabel.width , 20*Scale);
        self.companymobileLabel.text = [NSString stringWithFormat:@"移动电话：%@", model.telephone];
        self.companyEmailLabel.hidden = NO;
        self.companyEmailLabel.text = [NSString stringWithFormat:@"邮箱：%@", model.email];
        self.companyURLLabel.hidden = NO;
        self.companyURLLabel.text = [NSString stringWithFormat:@"网址：%@", model.company_info.website];
        self.educationLabel.hidden = YES;
        self.mobileLabel.hidden = YES;
        self.emailLabel.hidden = YES;
        
//        self.bottomLabel.frame = CGRectMake(25*Scale, self.weixinLabel.bottom, self.width - 35*Scale, 40*Scale);
        self.bottomLabel.text = [NSString stringWithFormat:@"公司地址：%@", model.company_info.address];
    } else { // 个人
//        _backView.image = [UIImage imageNamed:@"mingpian_geren"];
        if (model.skin_img && model.skin_img.length) {
            [self.backView sd_setImageWithURL:[NSURL URLWithString:model.skin_img] placeholderImage:[UIImage imageNamed:@"mingpian_geren"]];
        } else {
            _backView.image = [UIImage imageNamed:@"mingpian_geren"];
        }
        
        if (model.weixin && model.weixin.length) {
            _weixinLabel.hidden = NO;
            _weixinLabel.text = [NSString stringWithFormat:@"微信号: %@", model.weixin];
        } else {
            _weixinLabel.hidden = YES;
        }
        
        NSMutableAttributedString *namestr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"姓名：%@", model.name]];
        NSString *nickname = model.personal_info.nickname;
        if (nickname.length) {
            NSAttributedString *strq = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"（花名：%@）",nickname] attributes:@{NSForegroundColorAttributeName :[UIColor whiteColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:12]}];
            [namestr appendAttributedString:strq];
        }
        _nameLabel.attributedText = namestr;
        if ([model.personal_info.is_graduate isEqualToString:@"1"]) {
            _companyLabel.text = [NSString stringWithFormat:@"应届毕业生：%@", model.personal_info.speciality];
            self.companymobileLabel.hidden = NO;
            self.companymobileLabel.frame = CGRectMake(self.nameLabel.left, self.landlineLabel.bottom-40*Scale, self.nameLabel.width , 20*Scale);
            self.companymobileLabel.text = [NSString stringWithFormat:@"院校：%@", model.personal_info.school];
        } else {
            _companyLabel.text = [NSString stringWithFormat:@"现任/曾任：%@", model.position];
            self.companymobileLabel.hidden = YES;
            self.companymobileLabel.frame = CGRectMake(self.nameLabel.left, self.landlineLabel.bottom, self.nameLabel.width , 20*Scale);
        }
        
        self.landlineLabel.hidden = YES;
        self.companyEmailLabel.hidden = YES;
        self.companyURLLabel.hidden = YES;
        
        self.educationLabel.hidden = NO;
        self.educationLabel.text = [NSString stringWithFormat:@"学历：%@ 工作经验：%@",model.personal_info.education_cn,model.personal_info.experience_cn];
        self.mobileLabel.hidden = NO;
        self.mobileLabel.text = [NSString stringWithFormat:@"电话：%@",model.telephone];
        self.emailLabel.hidden = NO;
        self.emailLabel.text = [NSString stringWithFormat:@"邮箱：%@",model.email];
        self.bottomLabel.text = [NSString stringWithFormat:@"个人标签：%@",model.personal_info.tag_cn];
    }
}
/*
-(void)setModel:(LYBusinessCardModel *)model{
    [_iconImage sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:nil];
    [_codeImage sd_setImageWithURL:[NSURL URLWithString:model.weixin_img] placeholderImage:nil];
    if (model.type == 1) {
        //公司
        _backView.image = [UIImage imageNamed:@"mingpian_geren"];
        _weixinLabel.hidden = YES;
        NSMutableAttributedString *positionstr = [[NSMutableAttributedString alloc] initWithString:model.name];
        NSString *position = model.position;
        if (position.length) {
            NSAttributedString *strq = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"（%@）",position] attributes:@{NSForegroundColorAttributeName :[UIColor whiteColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:12]}];
            [positionstr appendAttributedString:strq];
        }
        _nameLabel.attributedText = positionstr;
        _companyLabel.text = model.company_info[@"full_name"];
        
        self.landlineLabel.hidden = NO;
        self.landlineLabel.text = [NSString stringWithFormat:@"公司座机：%@",model.company_info[@"landline_tel"]];
        self.companymobileLabel.hidden = NO;
        self.companymobileLabel.text = [NSString stringWithFormat:@"移动电话：%@",model.telephone];
        self.companyEmailLabel.hidden = NO;
        self.companyEmailLabel.text = [NSString stringWithFormat:@"邮箱：%@",model.email];
        self.companyURLLabel.hidden = NO;
        self.companyURLLabel.text = [NSString stringWithFormat:@"网址：%@",model.company_info[@"website"]];
        self.educationLabel.hidden = YES;
        self.mobileLabel.hidden = YES;
        self.emailLabel.hidden = YES;
        
        self.bottomLabel.text = [NSString stringWithFormat:@"公司地址：%@",model.company_info[@"address"]];
    }else{
        //个人
        _backView.image = [UIImage imageNamed:@"mingpian_qiye"];
        _weixinLabel.hidden = NO;
        _weixinLabel.text = [NSString stringWithFormat:@"微信号:model.weixin"];
        NSMutableAttributedString *namestr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"姓名：%@",model.name]];
        NSString *nickname = model.personal_info[@"nickname"];
        if (nickname.length) {
            NSAttributedString *strq = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"（花名：%@）",nickname] attributes:@{NSForegroundColorAttributeName :[UIColor whiteColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:12]}];
            [namestr appendAttributedString:strq];
        }
        _nameLabel.attributedText = namestr;
        _companyLabel.text = [NSString stringWithFormat:@"现任/曾任：%@",model.position];
        
        self.landlineLabel.hidden = YES;
        self.companymobileLabel.hidden = YES;
        self.companyEmailLabel.hidden = YES;
        self.companyURLLabel.hidden = YES;
        
        self.educationLabel.hidden = NO;
        self.educationLabel.text = [NSString stringWithFormat:@"学历：%@ 工作经验：%@",model.personal_info[@"education_cn"],model.personal_info[@"experience_cn"]];
        self.mobileLabel.hidden = NO;
        self.mobileLabel.text = [NSString stringWithFormat:@"%@",model.telephone];
        self.emailLabel.hidden = NO;
        self.emailLabel.text = [NSString stringWithFormat:@"邮箱：%@",model.email];
        self.bottomLabel.text = [NSString stringWithFormat:@"个人标签：%@",model.personal_info[@"tag_cn"]];
    }
}
*/

@end
